package com.hs.app.breakcall.view;

import com.hs.app.breakcall.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.widget.ProgressBar;
import android.widget.TextView;

public class Loading extends Activity {
	private int progressStatus = 0;
	private static int myProgress = 0;
	private int maxProgress = 0;
	private Handler hd = new Handler();
	private ProgressBar progressBar;
	private TextView textView;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.loading);
	}
	
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		myProgress = 0;
		textView = (TextView) this.findViewById(R.id.txtLoading);
		progressBar = (ProgressBar) this.findViewById(R.id.progressbarLoading);
		if(progressBar.getMax() == 0){
			progressBar.setMax(100);
		}
		maxProgress = progressBar.getMax();
		
		new Thread(new Runnable() {
			@Override
			public void run() {
				// TODO Auto-generated method stub
				while(progressStatus < maxProgress){
					progressStatus = progressTask();
					hd.post(new Runnable() {
						@Override
						public void run() {
							// TODO Auto-generated method stub
							progressBar.setProgress(progressStatus);
							textView.setText("Progress: " + progressStatus + "/" + maxProgress);
						}
					});
				}
//				hd.postDelayed(new Runnable() {
//					@Override
//					public void run() {
//						// TODO Auto-generated method stub
//						progressStatus = 0;
//						myProgress = 0;
//						finish();
//					}
//				}, 0);
			}
			
			private int progressTask(){
				try {
					Thread.sleep(1);
				} catch(InterruptedException e){
					e.printStackTrace();
				}
				return ++myProgress;
			}
		}).start();
		
		Intent intent = new Intent(Loading.this, Intro.class);
		
	}
}
